<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/jsp/taglib.jsp"%>
<!DOCTYPE html>
<html>
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>信息编辑窗体</title>
    <meta name="keywords" content="">
    <meta name="description" content="">

    <link rel="shortcut icon" href="favicon.ico"> <link href="${ctxStatic}/plugins/h+/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/style.min862f.css?v=4.1.0" rel="stylesheet">
    <link href="${ctxStatic}/plugins/h+/css/plugins/chosen/chosen.css" rel="stylesheet">
    <link href="${pageContext.request.contextPath}/resources/plugins/h+/css/plugins/jsTree/style.min.css" rel="stylesheet">
    <style>
        .jstree-open>.jstree-anchor>.fa-folder:before{content:"\f07c"}.jstree-default .jstree-icon.none{width:0}
    </style>
</head>
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">

                <div class="ibox-content">
                    <form onsubmit="return  false" class="form-horizontal m-t" id="bizpersonForm">
                        <input id="code" value="${category.code}" name="category.category_code" type="hidden">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-8">
                                <input id="category_name" value="${category.category_name}" name="category.category_name" class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">上级目录：</label>
                            <div class="col-sm-8">
                                <select id="category_first_select" data-placeholder="选择类目..." class="chosen-select" name="category.category_parent"    onchange="ajaxCategorySecond(this)"   class="form-control">
                                </select>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">排序：</label>
                            <div class="col-sm-8">
                                <input id="sort" value="${category.sort}" name="sort" class="form-control" type="text">
                            </div>
                        </div>

                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <input type="submit" class="btn btn-primary" value="提交" >
                                <%--<button id="btn_close"  class="btn btn-primary" type="button" data-dismiss="modal">关闭</button>--%>
                              <%--  <button id="transmit"  class="btn btn-primary" type="button">给父页面传值</button>--%>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/jquery.min.js?v=2.1.4"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/bootstrap.min.js?v=3.3.6"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/content.min.js?v=1.0.0"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/validate/messages_zh.min.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/demo/form-validate-demo.min.js"></script>
    <script src="${ctxStatic}/plugins/h+/js/plugins/chosen/chosen.jquery.js"></script>
    <script src="${pageContext.request.contextPath}/resources/plugins/h+/js/plugins/jsTree/jstree.js"></script>
    <script type="text/javascript" src="http://tajs.qq.com/stats?sId=9051096" charset="UTF-8"></script>

<script>

var areaData;
var index = parent.layer.getFrameIndex(window.name);
$(function () {
    ajaxCategoryFirst();
    $("#bizpersonForm").validate({
        submitHandler : function() {
            doSubmit();
        },
        rules:{
            person_name:{
                required:true,
                maxlength:50
            },
            phone:{
                required:true,
                checkPhone:true
            },
            number:{
                required:true,
                maxlength:50
            },
            notes:{
                required:false,
                maxlength:200,
            }

        },
        messages:{
            person_name:{
                required:"*必填！",
                maxlength:"*长度不能超过50位！",
            },
            phone:{
                required:"*必填！"
            },
            number:{
                required:"*必填！",
                maxlength:"*长度不能超过50位！",
            },
            notes:{
                required:"*必填！",
                maxlength:"*长度不能超过200位！",
            }
        },
        //是否在获取焦点时验证
        onfocusout:true,
        //是否在敲击键盘时验证
        //onkeyup:false,
        //提交表单后，（第一个）未通过验证的表单获得焦点
        focusInvalid:false,
        //当未通过验证的元素获得焦点时，移除错误提示
        focusCleanup:false,
    });

    //自定义正则表达示验证方法
    $.validator.addMethod("checkPhone",function(value,element,params){
        var checkPhone = /^1[3,5,7,8]\d{9}$/;
        return this.optional(element)||(checkPhone.test(value));
    },"*请输入正确的手机号码！");

});


function doSubmit()
{
    $.ajax( {
        url:'${pageContext.request.contextPath}/shop/doSaveBusiness.ac',// 跳转到 action
        data:$("#bizpersonForm").serialize(),
        type:'post',
        cache:false,
        dataType:'json',
        success:function(data) {
           if(data.success==true) {
               alert("操作成功！");

               parent.layer.close(index);
           }else {
               alert("操作失败!");
           }
        },
        error : function() {
            alert("操作失败！");
        }
    });
}

//加载一级类目
function ajaxCategoryFirst()
{
    $('#category_first_select').append('<option value="0">无</option>');
    $.ajax( {
        url:'${pageContext.request.contextPath}/shop/queryCategoryFirst.ac?guid='+new Date().getTime(),// 跳转到 action
        data:{},
        type:'post',
        cache:false,
//            dataType:'json',
        success:function(data) {
            data=eval("(" + data + ")");
            if (data.length>0)
            {
                var selected = '';
                for (var i=0;i<data.length;i++)
                {
                    var html = '<option value="'+data[i].category_code+'">'+data[i].category_name+'</option>';
                    $('#category_first_select').append(html);
                }
//                $('#category_first_select').chosen({
//                    no_results_text : "未找到此选项!",
//                    width:"100%"
//                });
                $('#category_first_select').chosen({
                    no_results_text : "未找到此选项!",
                    width:"100%"
                });
                $("#category_first_select").trigger("chosen:updated");
                //加载二级类目
                ajaxCategorySecond();
            }
        },
//            error : function() {
//                alert("操作失败！");
//            }
    });
}
</script>

</body>

</html>

